Project ラジコン戦車
https://gyazo.com/401ebbbccc12602c470bb3c66623e027
code:hoge.c
const int INPUT_PIN_1 = A0;
const int INPUT_PIN_2 = A1;
int VOLUME_1, VOLUME_2;
int power1, power2;
void setup() {
Serial.begin(9600);
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(PWM_PIN_1,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
pinMode(PWM_PIN_2,OUTPUT);
}
void analog1(){
int i;
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
for(i=0;i<256;i++){
analogWrite(PWM_PIN_1,i);
delay(20);
}
for(i=255;i>=0;i--){
analogWrite(PWM_PIN_1,i);
delay(20);
}
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
}
void analog2(){
int i;
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
for(i=0;i<256;i++){
analogWrite(PWM_PIN_2,i);
delay(20);
}
for(i=255;i>=0;i--){
analogWrite(PWM_PIN_2,i);
delay(20);
}
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
void analog3(){
int i;
VOLUME_1 = analogRead(INPUT_PIN_1);
Serial.print("Volume: ");
Serial.println(VOLUME_1);
power1 = VOLUME_1 / 4;
VOLUME_2 = analogRead(INPUT_PIN_2);
Serial.print("Volume2: ");
Serial.println(VOLUME_2);
power2 = VOLUME_2 / 4;
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
analogWrite(PWM_PIN_1,power1);
analogWrite(PWM_PIN_2,power2);
delay(20);
// for(i=255;i>=0;i--){
// analogWrite(PWM_PIN_1,i);
// analogWrite(PWM_PIN_2,i);
// delay(20);
// }
// digitalWrite(IN1,LOW);
// digitalWrite(IN2,LOW);
// digitalWrite(IN3,LOW);
// digitalWrite(IN4,LOW);
}
void loop() {
// analog1();
// analog2();
analog3();
}
とりあえず有線で前進後退までできるようになったが、すごく遅い.......